package com.qsmx.qingqiuticket.app.delegate.back;

import android.os.Bundle;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatEditText;

import com.lidroid.xutils.view.annotation.event.OnClick;
import com.qsmx.core.delegates.AtmosDelegate;
import com.qsmx.core.util.StringUtil;
import com.qsmx.core.util.dialog.DialogUtil;
import com.qsmx.core.util.storage.AtmosPreference;
import com.qsmx.qingqiuticket.app.R;
import com.qsmx.qingqiuticket.app.databinding.DelegatePasswordSettingBinding;
import com.qsmx.qingqiuticket.app.fusion.FusionPre;

import java.util.Objects;

public class BackPasswordSetDelegate extends AtmosDelegate {

    private DelegatePasswordSettingBinding mBinding;

    @Override
    public Object setLayout() {
        return R.layout.delegate_password_setting;
    }

    @Override
    public void onBindView(@Nullable Bundle savedInstanceState, View rootView) {

        mBinding = DelegatePasswordSettingBinding.bind(rootView);
        mBinding.btBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                getSupportDelegate().pop();
            }
        });

        mBinding.btSure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (StringUtil.isNotEmpty(Objects.requireNonNull(mBinding.etPassword.getText()).toString())) {
                    if (StringUtil.isNotEmpty(Objects.requireNonNull(mBinding.etPasswordAgain.getText()).toString())) {
                        if (mBinding.etPassword.getText().toString().equals(mBinding.etPasswordAgain.getText().toString())) {
                            AtmosPreference.addCustomStringPre(FusionPre.BACK_PASSWORD, mBinding.etPassword.getText().toString());
                            DialogUtil.showCardErrorDialog(getContext(), "密码设置成功！", "确定");
                        } else {
                            DialogUtil.showCardErrorDialog(getContext(), "两次输入的密码不同，请重新输入", "确定");
                        }
                    } else {
                        DialogUtil.showCardErrorDialog(getContext(), "密码不可为空", "确定");
                    }
                } else {
                    DialogUtil.showCardErrorDialog(getContext(), "密码不可为空", "确定");
                }
            }
        });

    }
}
